/*
 * TransactionBO.java
 *
 * Created on March 7, 2007, 1:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Data;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
 *
 * @author Danny Beutler
 */
public class TransactionBO {
    private String id;
    private String type;
    private String status="Pending";
    private Date date;
    private String customer;
    private PaymentBO payment;
    private String store;
    private String employee;
    private List<TransactionLineBO> txLines=new ArrayList<TransactionLineBO>();
    private String returnID;
    private double subTotal;
    private double tax;
    private double total;
    private boolean alreadyInDB=false;
    private boolean dirty =true;
    
    
    /** Creates a new instance of TransactionBO */
    public TransactionBO(String GUID) {
        this.id=GUID;
    }
    
    /** Gets the transaction GUID */
    public String getId() {
        return id;
    }
    
    /** Gets the transaction type */
    public String getType() {
        return type;
    }
    
    /** Sets the transaction type */
    public void setType(String type) {
        dirty=true;
        this.type = type;
    }
    
    /** Gets the transaction status */
    public String getStatus() {
        return status;
    }
    
    /** Sets the transaction status */
    public void setStatus(String status) {
        dirty=true;
        this.status = status;
    }
    
    /** Gets the transaction date */
    public Date getDate() {
        return date;
    }
    
    /** Sets the transaction date */
    public void setDate(Date date) {
        dirty=true;
        this.date = date;
    }
    
    /** Gets the transaction customer */
    public CustomerBO getCustomer() throws DataException{
        return CustomerDAO.getInstance().read(customer);
    }
    
    /** Sets the transaction customer */
    public void setCustomer(String customer) {
        dirty=true;
        this.customer = customer;
    }
    
    /** Gets the transaction payment */
    public PaymentBO getPayment() {
        return payment;
    }
    
    /** Sets the transaction payment */
    public void setPayment(PaymentBO payment) {
        dirty=true;
        this.payment = payment;
    }
    
    /** Gets the transaction store */
    public StoreBO getStore() throws DataException {
        return StoreDAO.getInstance().read(store);
    }
    
    /** Sets the transaction store */
    public void setStore(String store) {
        dirty=true;
        this.store = store;
    }
    
    /** Gets the transaction employee */
    public EmployeeBO getEmployee() throws DataException {
        return EmployeeDAO.getInstance().read(employee);
    }
    
    /** Sets the transaction employee */
    public void setEmployee(String employee) {
        dirty=true;
        this.employee = employee;
    }
    
    /** Gets the transaction subtotal */
    public double getSubtotal() {
        subTotal=0.0;
        for(int i=0;i<txLines.size();i++){
            subTotal+=txLines.get(i).getTotalPrice();
        }
        return subTotal;
    }
    
    /** Gets the transaction tax */
    public double getTax() {
        tax=0.0;
        tax=getSubtotal()*.06;
        
        return tax;
    }
    
    /** Gets the transaction total */
    public double getTotal() {
        total = getSubtotal() + getTax();
        
        return total;
    }
    
    
    /** Gets the transaction alreadyInDB variable */
    public boolean isAlreadyInDB() {
        return alreadyInDB;
    }
    
    /** Sets the transaction alreadyInDB variable */
    public void setAlreadyInDB(boolean alreadyInDB) {
        this.alreadyInDB = alreadyInDB;
    }
    
    /** Gets the transaction dirty variable  */
    public boolean isDirty() {
        return dirty;
    }
    
    /** Sets the transaction dirty variable */
    public void setDirty(boolean dirty) {
        this.dirty = dirty;
    }
    
    /** Gets the transaction line list  */
    public List<TransactionLineBO> getTxLines() {
        return txLines;
    }
    
    /** Sets the transaction line list */
    public void setTxLines(List<TransactionLineBO> txLines) {
        dirty=true;
        this.txLines = txLines;
    }
    
    /** Adds to the transaction Line List*/
    public void addTxLine(TransactionLineBO txLine){
        dirty=true;
        txLines.add(txLine);
    }
    
    /** Removes a transactionLine from the transaction Line List*/
    public void removeTxLine(TransactionLineBO txLine){
        dirty=true;
        txLines.remove(txLine);
    }
    
    
    /** Sets the transaction returnID*/
    public String getReturnID() {
        return returnID;
    }
    
    /** Gets the transaction returnID */
    public void setReturnID(String returnID) {
        dirty=true;
        this.returnID = returnID;
    }
    
    
    
}
